package tw.com.msig.b2c.car.insurance.service.impl;

import java.util.ArrayList;
import java.util.List;

import tw.com.msig.b2c.car.insurance.dao.PolicyDao;
import tw.com.msig.b2c.car.insurance.service.PolicyService;
import tw.com.msig.b2c.car.insurance.vo.InsItemVo;
import tw.com.msig.b2c.car.insurance.vo.PolicyVo;
import tw.com.msig.b2c.car.product.dao.PdtInsItemDao;
import tw.com.msig.b2c.car.product.vo.PdtInsItemVo;

public class PolicyServiceImpl implements PolicyService {

	
	private PolicyDao policyDao;
	
	private PdtInsItemDao pdtInsItemDao;
	
	
	public void setPolicyDao(PolicyDao policyDao) {
		this.policyDao = policyDao;
	}
	
	public void setPdtInsItemDao(PdtInsItemDao pdtInsItemDao) {
		this.pdtInsItemDao = pdtInsItemDao;
	}

	@Override
	public List<PolicyVo> getAll() {
		return policyDao.findAll();
	}

	@Override
	public PolicyVo getById(long id) {
		return policyDao.findById(id);
	}

	@Override
	public void insert(PolicyVo policyVo) {
		policyDao.insert(policyVo);
	}

	@Override
	public void update(PolicyVo policyVo) {
		policyDao.update(policyVo);
	}

	@Override
	public void delete(PolicyVo policyVo) {
		policyDao.delete(policyVo);
	}

	@Override
	public List<InsItemVo> getInsItems(PolicyVo policyVo) {
		
		List<InsItemVo> result = new ArrayList<InsItemVo>();
		
		List<PdtInsItemVo> pdtInsItems = pdtInsItemDao.findAll();
		
		for(PdtInsItemVo pdtInsItem:pdtInsItems) {
			InsItemVo insItemVo = new InsItemVo();
			
			insItemVo.setCode(pdtInsItem.getCode());
			insItemVo.setDescription(pdtInsItem.getDescription());
			insItemVo.setAmounts("2000000");
			if("21".equals(insItemVo.getCode())) {
				insItemVo.setPremium(1200);
			} else if("31".equals(insItemVo.getCode())) {
				insItemVo.setPremium(328);
			} else if("32".equals(insItemVo.getCode())) {
				insItemVo.setPremium(828);
			}
			
			
			result.add(insItemVo);
		}
		
		
		
		return result;
		
	}
	
	
	
	
	
	
	
	
	

}
